﻿@model PagedList.IPagedList<VOD.Models.Comment>

<h1>所有评论</h1>
<table>
    <tr class="thead">
        <th width="130">视频</th>
        <th width="80">用户</th>
        <th width="250">评论</th>
        <th width="120">时间</th>
        <th width="40"></th>
    </tr>

@foreach (var item in Model.Where(c=>c.ParentID==null)) {
    <tr>
        <td>
            @Html.ActionLink(item.Video.Name,"Play", "Video", new { id = item.VideoID }, new { target = "_blank" })
        </td>
        <td>
            @if (item.UserID == Guid.Empty)
            {
                @:匿名 
            }
            else { 
                var userName=Membership.GetUser(item.UserID).UserName;
                @Html.ActionLink(userName,"Details", "UserMgr", new { user = userName }, new { target = "_blank" })
            }
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.CommentContent)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PostTime)
        </td>
        <td>
            @Html.ActionLink("删除", "Delete", new { id = item.CommentID })
        </td>
    </tr>
    if (Model.Any(c => c.ParentID == item.CommentID))
    {
    <tr align="right">
        <td colspan="5">
            <table>
                <tr class="thead">
                    <th width="80">用户</th>
                    <th width="250">评论</th>
                    <th width="120">时间</th>
                    <th width="35"></th>
                </tr>
                @foreach(var com2 in Model.Where(c=>c.ParentID==item.CommentID))
                {
                    <tr>
                        <td>
                            @if (com2.UserID == Guid.Empty)
                            {
                                @:匿名 
                            }
                            else { 
                                var userName=Membership.GetUser(com2.UserID).UserName;
                                @Html.ActionLink(userName,"Details", "UserMgr", new { user = userName }, new { target = "_blank" })
                            }
                        </td>
                        <td>@com2.CommentContent</td>
                        <td>@com2.PostTime</td>
                        <td>@Html.ActionLink("删除", "Delete", new { id = com2.CommentID })</td>
                    </tr>
                }
            </table>
        </td>
    </tr>
    }
}
</table>

@*分页*@
@if (Model.PageCount > 1)
{
<div class="paging">
    @if (Model.IsFirstPage)
    {
        @:<a>|<</a>
        @:<a><</a>
    }
    else
    {
        @Html.ActionLink("|<", "Index", new { page = 1 })
        @Html.ActionLink("<", "Index", new { page = Model.PageNumber - 1 })
    }
    @for (int i = 1; i <= Model.PageCount; i++)
    {
        @Html.ActionLink(i.ToString(), "Index", new { page = i }) 
    }
    @if (Model.IsLastPage)
    {
        @:<a>></a>
        @:<a>>|</a>
    }
    else
    {
        @Html.ActionLink(">", "Index", new { page = Model.PageNumber + 1 }) 
        @Html.ActionLink(">|", "Index", new { page = Model.PageCount })
    }
</div>
}
